package com.tvunetworks.center.device.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
/**
 * @author Etan Yang
 * @create: 2021/10/13 16:04
 */

public interface SyncTvuDeviceMapper {

   /**
    * 查询出tvu_device表不存在的数据
    * @return List
    */
   //查询出tvu_device表不存在的数据	
   @Select("select ttds.peer_id from (select DISTINCT peer_id from tvu_token_device ttd where delete_flag = 0 and expire_flag = 0  and type = 'T' and description != 'fromPPCode' and not EXISTS (select 1 from tvu_device td where td.peer_id = ttd.peer_id )) ttds where EXISTS (select 1 from sychdevice s where s.DeviceId = ttds.peer_id ) LIMIT 50")
    List<String> getNotExistTvuDeviceData();

   /**
    *
    * @param deviceId deviceId
    * @return  int
    */
   @Select("select count(0) from sychdevice where deviceId = #{deviceId}")
    int selectSychdeviceByPeerId(@Param(value = "deviceId") String deviceId);

   /**
    * 将数据更新到tvu_device表中
    * @param deviceId deviceId
    * @return int
    */
   //将数据更新到tvu_device表中
   @Update("update sychdevice set TimeStamp = UNIX_TIMESTAMP(NOW()) * 1000  where  DeviceId = #{deviceId} ")
    int updateToTvuDevice(@Param(value = "deviceId") String deviceId);
   
}
